﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneralDFS.BusinessLogical
{
    /// <summary>
    /// 主要负责dataNode本地对文件块写入数据
    /// </summary>
    public class BlockWriter
    {
        private FileStream fileStream;

        public BlockWriter(Guid guid)
        {
            string blockPath = FSVolume.GetInstance().GetFilePath(guid);
            if (blockPath != null)
                fileStream = new FileStream(blockPath, FileMode.Open, FileAccess.Write);
            else
            {
                LogUtil.LogError(
                    string.Format("********Cannot Find Block:{0}******** /n********When InitBlockReader********",
                                  guid.ToString()));
            }
        }
        public void Write(byte[] buff, int offset, int count)
        {
            fileStream.Write(buff,offset,count);
        }
        public void Seek(long offset)
        {
            fileStream.Seek(offset, SeekOrigin.Begin);
        }
    }
}
